-- Copyright (c) 2015,2016 Lucky Byte, Inc.
--
-- Summary : ACP 交易判定
--
-- Author  : 吴小虎 <xiaohu@lucky-byte.com>
-- Since   : 2016.4.29
--
-- History
--  * 2015.5.6 : 创建此文件
--

-- ACP 交易清单
--
local _trcode_table = {
    ['00-00'] = { code = 't10', name = '交易查询' },
    ['71-00'] = { code = 'ttt', name = '余额查询' },
    ['73-01'] = { code = 'ttt', name = '账单查询-便民缴费' },
    ['73-02'] = { code = 'ttt', name = '账单查询-网上缴税' },
    ['73-03'] = { code = 'ttt', name = '账单查询-网上缴税' },
    ['73-04'] = { code = 'ttt', name = '账单查询-保险缴费' },
    ['73-05'] = { code = 'ttt', name = '账单查询-现金缴费' },
    ['73-06'] = { code = 'ttt', name = '账单查询-渠道汽车票' },
    ['75-00'] = { code = 'ttt', name = '绑定关系查询' },
    ['01-01'] = { code = 't20', name = '自助消费' },
    ['01-02'] = { code = 't20', name = '订购' },
    ['01-03'] = { code = 't20', name = '分期付款' },
    ['31-00'] = { code = 'ttt', name = '消费撤销' },
    ['04-00'] = { code = 'ttt', name = '退货' },
    ['02-01'] = { code = 'ttt', name = '预授权' },
    ['02-02'] = { code = 'ttt', name = '订购预授权' },
    ['02-03'] = { code = 'ttt', name = '担保消费' },
    ['32-00'] = { code = 'ttt', name = '预授权撤销' },
    ['03-00'] = { code = 'ttt', name = '预授权完成' },
    ['33-00'] = { code = 'ttt', name = '预授权完成撤销' },
    ['94-01'] = { code = 'ttt', name = '消费交易脚本通知' },
    ['94-02'] = { code = 'ttt', name = '余额查询脚本通知' },
    ['94-03'] = { code = 'ttt', name = '电子现金指定账户圈存' },
    ['94-04'] = { code = 'ttt', name = 'IC卡脱机消费通知' },
    ['13-01'] = { code = 'ttt', name = '便民缴费' },
    ['13-02'] = { code = 'ttt', name = '网上缴税' },
    ['13-03'] = { code = 'ttt', name = '信用卡还款' },
    ['13-04'] = { code = 'ttt', name = '保险缴费' },
    ['13-05'] = { code = 'ttt', name = '现金缴费-单销账' },
    ['13-06'] = { code = 'ttt', name = '渠道汽车票' },
    ['11-00'] = { code = 'ttt', name = '代收' },
    ['12-00'] = { code = 't40', name = '实时代付',
        settl = true, trctl = true
    },
    ['05-02'] = { code = 'ttt', name = '指定账户圈存' },
    ['14-01'] = { code = 'ttt', name = '普通转账' },
    ['21-01'] = { code = 'ttt', name = '批量退货' },
    ['21-02'] = { code = 'ttt', name = '批量代收' },
    ['21-03'] = { code = 'ttt', name = '批量代付' },
    ['22-01'] = { code = 'ttt', name = '批量退货查询' },
    ['22-02'] = { code = 'ttt', name = '批量代收查询' },
    ['22-03'] = { code = 'ttt', name = '批量代付查询' },
    ['76-01'] = { code = 'ttt', name = '对账文件下载' },
    ['72-01'] = { code = 'ttt', name = '实名认证' },
    ['72-02'] = { code = 'ttt', name = '免验建立绑定关系' },
    ['72-10'] = { code = 'ttt', name = '前台模式实名认证' },
    ['74-00'] = { code = 'ttt', name = '撤销绑定关系' },
    ['77-00'] = { code = 'ttt', name = '开通短信' },
    ['77-01'] = { code = 'ttt', name = '实名认证短信' },
    ['77-02'] = { code = 'ttt', name = '消费短信' },
    ['77-03'] = { code = 'ttt', name = '代扣短信' },
    ['77-04'] = { code = 'ttt', name = '预授权短信' },
    ['77-05'] = { code = 'ttt', name = '南卡开通短信' },
    ['78-00'] = { code = 'ttt', name = '开通账号查询' },
    ['78-01'] = { code = 'ttt', name = '开通手机号查询' },
    ['78-02'] = { code = 'ttt', name = '开通订单号查询' },
    ['79-00'] = { code = 'ttt', name = '默认开通交易' },
    ['79-02'] = { code = 'ttt', name = '验密开通交易' },
}


-- 通过报文字段内容获取其对应的交易名称等信息
lib071.trinfo = function(packet)
    assert(packet._class == 'Packet071', string.format(
        'lib071.trinfo() 需要 Packet071 报文，当前报文类型为[%s]', packet._class))

    local _txn_type = packet.get('txnType')
    local _txn_sub_type = packet.get('txnSubType')

    if not _txn_type or not _txn_sub_type then
        logger.warn('报文中缺少 txnType 或 txnSubType, 不能获取交易信息.')
        return {
            code = 'ttt', name = '未知交易'
        }
    end
    local _key = string.format('%s-%s', _txn_type, _txn_sub_type)
    return _trcode_table[_key] or {
        code = 'ttt', name = '未知交易'
    }
end
